# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: http://doc.scrapy.org/en/latest/topics/item-pipeline.html

import scrapy
import MySQLdb
import MySQLdb.cursors
import sys
sys.path.append("..")
from dar.dar import Dar
from coin.items.items import CoinItem
from coin.items.price_item import PriceItem

class CoinPipeline(object):
    def __init__(self):
        pass

    def process_item(self, item, spider):
        if isinstance(item, CoinItem):
            return self.process_coin_items(item, spider);
        elif isinstance(item, PriceItem):
            return self.process_price_items(item, spider);

    def process_coin_items(self, item, spider):
        coin = Dar('coin')
        on = {'symbol': item['symbol']}
        coin.saveOn(item, on)
        return item

    def process_price_items(self, item, spider):
        price = Dar('coin_market_price')
        if item:
            price.add(item)
        return item
